package com.qztech.bluetooth;

import com.qztech.utils.YzDebug;

import java.util.ArrayList;
import java.util.Collections;
import java.util.UUID;

/**
 * @author:zhanghb
 * @date:2019/5/3
 * @email:z23bin@163.com
 **/
public class BluetoothConfig {
    private static UUID NOTIFY_CHARACTER_UUID;
    private static UUID SERVICE_UUID;
    private static UUID WRITE_CHARACTER_UUID;
    private static UUID READ_CHARACTER_UUID;
    private static final ArrayList<String> NAMES = new ArrayList<>();
    public static void init(String serviceUUID,
                            String writeCharacterUUID,
                            String notifyCharacterUUID,
                            String readCharacterUUID,
                            String ... names) {
        NAMES.clear();
        if (names != null) {
            for (String name : names) {
                NAMES.add(name.toUpperCase());
            }
        }
        SERVICE_UUID = UUID.fromString(serviceUUID);
        if (writeCharacterUUID != null) {
            WRITE_CHARACTER_UUID = UUID.fromString(writeCharacterUUID);
        }
        if (notifyCharacterUUID != null) {
            NOTIFY_CHARACTER_UUID = UUID.fromString(notifyCharacterUUID);
        }
        if (readCharacterUUID != null) {
            READ_CHARACTER_UUID = UUID.fromString(readCharacterUUID);
        }
    }

    public static UUID getNotifyCharacterUuid() {
        return NOTIFY_CHARACTER_UUID;
    }

    public static UUID getServiceUuid() {
        return SERVICE_UUID;
    }

    public static UUID getWriteCharacterUuid() {
        return WRITE_CHARACTER_UUID;
    }

    public static UUID getReadCharacterUuid() {
        return READ_CHARACTER_UUID;
    }
    public static boolean isAvailableName(String name){
        if (name == null) return false;
//        for (String s : NAMES) {
//            YzDebug.d("isAvailableName:"+ s +"  " + name +" " + s.equals(name.toUpperCase()));
//        }
//        YzDebug.d("BT","isAvailableName:"+ name +" " + NAMES.contains(name.toUpperCase()));
        return NAMES.contains(name.toUpperCase());
    }
//    public static String getName() {
//        return NAME;
//    }
}
